<?php

namespace app\mobile\controller;

use app\common\model\Category;
use think\Controller;
use app\admin\model\News as NewsModel;

class News extends Base
{
    function _initialize()
    {
        parent::_initialize();
        $this->model = new NewsModel();

    }

    public function index()
    {
        $cate = Category::where('type', 'news')->select();
        $cid = $this->request->param('cid');
        $where = [];
        $query = [];
        if ($cid) {
            $where["category_id"] = $cid;
            $query['cid'] = $cid;
        }
        $data = newsModel::where($where)->order('id', 'desc')->paginate([
            'query' => $query,
            'list_rows' => 5,
        ]);
        $this->assign([
            'data' => $data,
            'cid' => $cid,
            'cate' => $cate,
        ]);
        return $this->fetch();
    }


}